import { ObjCreate } from "../../common/ObjCreate";
import { ArenaPlayerResult } from "./ArenaPlayerResult";
import { ArenaGroupMiniResult } from "./ArenaGroupMiniResult";
import { EBattleResult } from "../../../../../Message/Public/EBattleResult";
import { SArenaPlayerResult } from "../../../../../Message/Public/SArenaPlayerResult";
import { ArenaGroupData } from "../ArenaData/ArenaGroupData";
import { Cache } from "../../../cache/Cache";
import { LoaderHelp } from "../../../../common/display/LoaderHelp";
import { GlobalClass } from "../../../../../com/mui/core/GlobalClass";
import { ImagesConst } from "../../../resource/ImagesConst";
type int = number;
//class ArenaGroupResult
    
    export  class ArenaGroupResult /* flash.display.Sprite */
    {
        constructor()
        {
            
            this._aryPlayerResult = new Array<any>();
            this.init();
            return;
        }

        /* internal  */init(): void
        {
            var loc2=null;
            ObjCreate.createBg(0, 0, 170, 165, this);
            this._resultBmp = new Object /* flash.display.Bitmap */();
            this._spNormalContainer = new Object /* flash.display.Sprite */();
            this.addChild(this._spNormalContainer);
            var loc1=0;
            while (loc1 < this._groupLength) 
            {
                loc2 = new ArenaPlayerResult();
                ObjCreate.setObjAttri(loc2, 0, 5 + 110 * loc1, -1, -1, this._spNormalContainer);
                this._aryPlayerResult.push(loc2);
                ++loc1;
            }
            this._groupMiniResult = new ArenaGroupMiniResult();
            this._groupMiniResult.visible = false;
            ObjCreate.setObjAttri(this._groupMiniResult, 0, 0, -1, -1, this);
            ObjCreate.setObjAttri(this._resultBmp, 5, 5, -1, -1, this);
            return;
        }

        public updateResult(arg1: Array<any>, arg2: EBattleResult, arg3: Boolean=false, arg4: int=3): void
        {
            var result: Array<any>;
            var isWin: EBattleResult;
            var isFina: Boolean=false;
            var leftLife: int=3;
            var playerResult: ArenaPlayerResult;
            var splayerResult: SArenaPlayerResult;
            var selfResult: SArenaPlayerResult;
            var totalHurt: int;
            var totalCure: int;
            var averageCapabili: int;
            var i: int;
            var arenaGroupData: ArenaGroupData;

            var loc1;
            playerResult = null;
            splayerResult = null;
            selfResult = null;
            result = arg1;
            isWin = arg2;
            isFina = arg3;
            leftLife = arg4;
            totalHurt = 0;
            totalCure = 0;
            averageCapabili = 0;
            if (!result && result.length == 0) 
            {
                return;
            }
            i = 0;
            while (i < result.length) 
            {
                splayerResult = result[i] as SArenaPlayerResult;
                if (splayerResult.miniPlayer.entityId.id == Cache.instance.role.entityInfo.entityId.id) 
                {
                    selfResult = splayerResult;
                }
                totalHurt = totalHurt + splayerResult.totalHurt;
                totalCure = totalCure + splayerResult.totalCure;
                averageCapabili = averageCapabili + splayerResult.combatCapabilities;
                if (!(i >= this._aryPlayerResult.length)) 
                {
                    playerResult = this._aryPlayerResult[i] as ArenaPlayerResult;
                    playerResult.updateResult(splayerResult, isFina);
                }
                ++i;
            }
            averageCapabili = averageCapabili / result.length;
            arenaGroupData = new ArenaGroupData();
            arenaGroupData.totalCure = totalCure;
            arenaGroupData.totalHurt = totalHurt;
            arenaGroupData.averageCapabili = averageCapabili;
            arenaGroupData.markInBattle = selfResult ? selfResult.markInBattle : splayerResult.markInBattle;
            this._groupMiniResult.updateResult(arenaGroupData);
            if (result.length != 1) 
            {
                this._groupMiniResult.visible = true;
                this._spNormalContainer.visible = false;
            }
            else 
            {
                this._groupMiniResult.visible = false;
                this._spNormalContainer.visible = true;
            }
            if (splayerResult) 
            {
                LoaderHelp.addResCallBack("arena", (): void
                {
                    if (isWin.value() != EBattleResult._EBattleResultWin) 
                    {
                        _resultBmp.bitmapData = GlobalClass.getBitmapData(ImagesConst.ArenaLose);
                    }
                    else 
                    {
                        _resultBmp.bitmapData = GlobalClass.getBitmapData(ImagesConst.ArenaWin);
                    }
                    return;
                })
            }
            return;
        }

        /* internal */ /* const */_groupLength: int=1;

        /* internal */ /* var */_resultBmp: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_aryPlayerResult: Array<any>;

        /* internal */ /* var */_groupMiniResult: ArenaGroupMiniResult;

        /* internal */ /* var */_spNormalContainer: Object /* flash.display.Sprite */;
    }
